﻿using System;

namespace 贪吃蛇
{
    class Diffuculty : Game
    {
        public override void diffuculty()
        {
            Console.Clear();
            int minIndex = 0; int maxIndex = 3;
            int menuIndex = minIndex;
            writeMenu(menuIndex);
            while (Game.scene == E_Scene.Diffuculty)
            {
                switch (Console.ReadKey(true).Key)
                {
                    case ConsoleKey.W:
                    case ConsoleKey.UpArrow:
                        menuIndex--;
                        if (menuIndex < minIndex)
                        {
                            menuIndex = maxIndex;
                        }
                        writeMenu(menuIndex);
                        break;
                    case ConsoleKey.S:
                    case ConsoleKey.DownArrow:
                        menuIndex++;
                        if (menuIndex > maxIndex)
                        {
                            menuIndex = minIndex;
                        }
                        writeMenu(menuIndex);
                        break;
                    case ConsoleKey.Enter:
                    case ConsoleKey.Spacebar:
                        if ((E_Diffuculty)menuIndex == E_Diffuculty.Easy)
                            Play.speed = E_Speed.Slow;
                        else if ((E_Diffuculty)menuIndex == E_Diffuculty.Normal)
                            Play.speed = E_Speed.Normal;
                        else if ((E_Diffuculty)menuIndex == E_Diffuculty.Diffucult)
                            Play.speed = E_Speed.Quick;
                        else
                            Play.speed = E_Speed.VeryQuick;
                        Game.scene = E_Scene.Start;
                        break;
                    default:
                        break;
                }
            }
        }
        public void writeMenu(int index)
        {
            Console.Clear();
            //标题
            E_Diffuculty diff = (E_Diffuculty)index;
            Console.SetCursorPosition(Game.bufWidth / 2 - 2, Game.bufHeight / 6);
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine("难度选择");
            //选项1
            Console.ForegroundColor = diff == E_Diffuculty.Easy ? ConsoleColor.Red : ConsoleColor.White;
            Console.SetCursorPosition(Game.bufWidth / 2 - 1, Game.bufHeight * 1/ 3);
            Console.WriteLine("简单");
            //选项2
            Console.ForegroundColor = diff == E_Diffuculty.Normal ? ConsoleColor.Red : ConsoleColor.White;
            Console.SetCursorPosition(Game.bufWidth / 2 - 1, Game.bufHeight * 1 / 2);
            Console.WriteLine("正常");
            Console.ForegroundColor = diff == E_Diffuculty.Diffucult ? ConsoleColor.Red : ConsoleColor.White;
            Console.SetCursorPosition(Game.bufWidth / 2 - 1, Game.bufHeight * 4 / 6);
            Console.WriteLine("困难");
            Console.ForegroundColor = diff == E_Diffuculty.Insane ? ConsoleColor.Red : ConsoleColor.White;
            Console.SetCursorPosition(Game.bufWidth / 2 - 1, Game.bufHeight * 5 / 6);
            Console.WriteLine("疯狂");
        }
    }
    enum E_Diffuculty
    {
        Easy, Normal, Diffucult, Insane
    }
}
   